package fss.common.communication;

import fss.util.rmi.RmiId;
import java.util.LinkedList;
import java.util.Queue;

/**
 *
 * @author Meagan Griffin
 */
public class FileServiceStatus extends Status
{
  /** The download request status queue for the File Server Service. */
  private Queue<DownloadRequest> mDownloadQueue;

  /**
   * constructor FileServiceStatus()
   *   Creates a new instance of FileServiceStatus, the status object for the 
   *   File Server Service.
   */
  public FileServiceStatus()
  {
    super();
    this.mDownloadQueue = new LinkedList<DownloadRequest>();
  } // end constructor FileServiceStatus


  /**
   * method addDownloadRequest(RmiId aId, String aFileName)
   *   Adds a new download request to the download queue.
   * @param aId RmiId The ID of the new download request.
   * @param aFileName String The name of the file to be downloaded.
   */
  public void addDownloadRequest(RmiId aId, String aFileName)
  {
    DownloadRequest tRequest = new DownloadRequest(aId, aFileName);
    this.mDownloadQueue.add(tRequest);
  } // end method addDownloadRequest


  /**
   * method getFileServiceLoad()
   *   Returns the number of download requests currently waiting to be serviced.
   * @return int The number of download requests waiting to be serviced.
   */
  public int getFileServiceLoad()
  {
    return this.mDownloadQueue.size();
  } // end method getFileServiceLoad


  /**
   * public inner class DownloadRequest
   *   Container class for the data provided in a download request.
   */
  public class DownloadRequest
  {
    public final RmiId mRmiId;
    public final String mFileName;
    public EDownloadStatus mDownloadStatus;
    public /**final*/ int mTotalBlocks;
    public int mCurrentBlocks;

    /**
     * constructor DownloadRequest(RmiId aId, String aFileName)
     * @param aId RmiId The ID of the service making the request.
     * @param aFileName String The name of the file to be downloaded.
     */
    public DownloadRequest(RmiId aId, String aFileName)
    {
      this.mRmiId = aId;
      this.mFileName = aFileName;
      this.mDownloadStatus = EDownloadStatus.NOT_STARTED;
      /** TODO:: Find out how many blocks of data are needed for this file. */
      this.mTotalBlocks = 0;
      this.mCurrentBlocks = 0;
    } // end constructor DownloadRequest
  } // end public inner class DownloadRequest
  
  /**
   * public static enum DownloadStatus
   *   The enumeration of Download Status types.
   */
  public static enum EDownloadStatus
  {
    IN_PROGRESS,
    NOT_STARTED,
    COMPLETED;
  }
} // end class FileSeviceStatus
